<%@ page import="com.po.Note" %>
<%@ page import="java.util.List" %>
<%@ page import="com.po.User" %>
<%@ page import="com.dao.NoteDao" %>
<%@ page import="com.dao.InboxDao" %>
<%@ page isErrorPage="true" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<title>公开信封中的纸条</title>
<%
    HttpSession session1 = request.getSession(false);
    String envelope_name = null;
    if (session1 == null || session1.getAttribute("id") == null) {
        response.sendRedirect(request.getContextPath() + "/index.jsp");
    }
    List<Integer> myLike = (List<Integer>) session.getAttribute("myLike");
    int envelopeId = (int) session.getAttribute("envelopeId");
    String envelopeName = (String) session.getAttribute("envelopeName");
    List<Integer> frozenUsers = (List<Integer>) request.getAttribute("frozenId");
%>
<h3>纸条如下:</h3>
<table>
    <tr>
        <td>引用内容</td>
        <td>纸条名字</td>
        <td colspan="3">纸条内容</td>
        <td>引用纸条</td>
        <td>创建时间</td>
        <td>获赞数量</td>
        <td>点赞</td>
        <td></td>
        <%
            if ("administrator".equals(session.getAttribute("duty"))) {
        %>

        <td>管理员权限</td>
        <%
            }
        %>
    </tr>
    <%
        List<Note> notes = (List<Note>) request.getAttribute("notes");
        if (!notes.isEmpty()) {
            for (Note note : notes) {
    %>
    <tr>
        <%
            if (!"无".equals(note.getQuote())) {
        %>
        <td><a href="<%=request.getContextPath()%>/quoteNote?content=<%=note.getQuote()%>"><%=note.getQuote()%>
        </a>
        </td>
        <%
        } else {
        %>
        <td></td>
        <%
            }
        %>
        <td><%=note.getNote_name()%>
        </td>
        <td colspan="3"><%=note.getContent()%>
        </td>
        <td>
            <button onclick="window.location.href='<%=request.getContextPath()%>/quoteEnvelope?note_name=<%=note.getNote_name()%>&note_id=<%=note.getNote_id()%>'">
                引用
            </button>
        </td>
        <td><%=note.getCreate_time()%>
        </td>
        <td><%=note.getPriase_number()%>
        </td>
        <%
            if (myLike.contains(note.getNote_id())) {
        %>
        <td>
            <button onclick="window.location.href
                    ='<%=request.getContextPath()%>/givePraise?envelope_id=<%=envelopeId%>&envelope_name=<%=envelopeName%>&note_id=<%=note.getNote_id()%>&note_name=<%=note.getNote_name()%>&state=dislike';CancelPraise()">
                取消
            </button>
        </td>
        <%
        } else {
        %>
        <td>
            <button onclick="window.location.href
                    ='<%=request.getContextPath()%>/givePraise?envelope_id=<%=envelopeId%>&envelope_name=<%=envelopeName%>&note_id=<%=note.getNote_id()%>&note_name=<%=note.getNote_name()%>&state=like';GivePraise()">
                点赞
            </button>
        </td>
        <%
            }
        %>
        <td>
            <button onclick="window.location.href='<%=request.getContextPath()%>/openNote/comment?note_id=<%=note.getNote_id()%>&note_name=<%=note.getNote_name()%>&note_content=<%=note.getContent()%>'">
                评论区
            </button>
        </td>
        <%
            if ("administrator".equals(session.getAttribute("duty"))) {
                if (!frozenUsers.contains(NoteDao.getUserId(note.getNote_id()))) {
        %>
        <td>
            <button onclick="window.location.href='<%=request.getContextPath()%>/setFreezing?envelope_id=<%=envelopeId%>&envelope_name=<%=envelopeName%>&note_id=<%=note.getNote_id()%>';Freezing()">
                冻结用户
            </button>
        </td>
        <%
        } else {
        %>
        <td>已被冻结</td>
        <%
            }
        %>
        <td>
            <button>删除纸条</button>
        </td>
        <%
            }
        %>
    </tr>
    <%
            }
        }
    %>
</table>
<style>
    table {
        width: 650px;
        margin: auto;
        border: pink 1px solid;
        border-spacing: 0px;
        border-collapse: collapse;
    }

    td {
        border: pink 1px solid;
    }

    body {
        background-image: url("../picture/new.jpg");
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center center;
        background-size: 100% 100%;
    }
</style>
<hr>
<a href="<%=request.getContextPath()%>/leaveEnvelope">返回总信封页面</a>

<script type="text/javascript">
    function GivePraise() {
        alert("点赞成功");
    }

    function CancelPraise() {
        alert("取消点赞成功");
    }

    function Freezing() {
        alert("冻结成功");
    }
</script>


